package com.online.system.utils;



import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;
import java.util.UUID;

public class JwtUtil {
    public static String encrypt(Map map ,Date dateOut){
        Date date=new Date();
        JwtBuilder jwtBuilder= Jwts.builder().setId(UUID.randomUUID().toString())
                .setSubject("JWT")
                .setIssuedAt(date)
                .setExpiration(dateOut)
                .setClaims(map)
                .signWith(SignatureAlgorithm.HS256,"online");
        return jwtBuilder.compact();
    }
    public static Map decrypt(String token){
        Claims claims=Jwts.parser().setSigningKey("online").parseClaimsJws(token).getBody();
        return claims;
    }
}
